home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / demos / RGBAandCI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  2.7 KB  |  138 lines

  1. /* Copyright (c) Silicon Graphics, Inc. 1996 */
  2.  
  3. /*
  4.    Demonstrate using combinations of single/double and index/rgb simultaneously.
  5.    G. Edwards, SG UK,  Jan 04 94.
  6. */
  7.  
  8. #include <GL/gl.h>
  9. #include <GL/glut.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14.  
  15. GLboolean si = GL_FALSE, sr = GL_FALSE, di = GL_FALSE, dr = GL_FALSE;
  16.  
  17. #define  EQ(str1, str2)  (strcmp((str1),(str2)) == 0)
  18. #define NEQ(str1, str2)  (strcmp((str1),(str2)) != 0)
  19.  
  20. void
  21. drawSIscene( GLvoid )
  22. {
  23.     glClearIndex(15);
  24.     glClear(GL_COLOR_BUFFER_BIT);
  25. }
  26.  
  27. void
  28. drawDIscene( GLvoid )
  29. {
  30.     glClearIndex(5);
  31.     glClear(GL_COLOR_BUFFER_BIT);
  32.     glutSwapBuffers();
  33. }
  34.  
  35. void
  36. drawSRscene( GLvoid )
  37. {
  38.         glClearColor(0.2, 0.5, 0.7, 1.0);
  39.     glClear(GL_COLOR_BUFFER_BIT);
  40. }
  41.  
  42. void
  43. drawDRscene( GLvoid )
  44. {
  45.         glClearColor(0.5, 0.5, 0.5, 1.0);
  46.     glClear(GL_COLOR_BUFFER_BIT);
  47.     glutSwapBuffers();
  48. }
  49.  
  50. void
  51. keyboard( GLubyte key, GLint x, GLint y )
  52. {
  53.     if (key == 27) /* escape */
  54.         exit(0);
  55. }    
  56.  
  57. void main(int argc, char *argv[])
  58. {
  59.     int i = 0;
  60.  
  61.     glutInit( &argc, argv );
  62.  
  63. /* Help */
  64.  
  65.     if (argc < 2)
  66.     {
  67.         fprintf(stderr, "Usage: %s [si] [sr] [di] [dr]\n", argv[0]);
  68.         exit (-1);
  69.     }
  70.  
  71. /* Pick window modes from command line */
  72.  
  73.     while (++i < argc)
  74.     {
  75.         if (EQ(argv[i], "si"))
  76.             si = GL_TRUE;
  77.         if (EQ(argv[i], "sr"))
  78.             sr = GL_TRUE;
  79.         if (EQ(argv[i], "di"))
  80.             di = GL_TRUE;
  81.         if (EQ(argv[i], "dr"))
  82.             dr = GL_TRUE;
  83.     }
  84.  
  85. /* Single buffered cmap */
  86.  
  87.     if (si)
  88.     {
  89.         glutInitDisplayMode(GLUT_INDEX | GLUT_SINGLE);
  90.         glutInitWindowPosition(100, 100); 
  91.     glutInitWindowSize( 400, 100);
  92.         glutCreateWindow("Single Cmap");
  93.         glutSetColor(15, 0.5, 0.5, 0.5);
  94.         glutDisplayFunc( drawSIscene );
  95.     glutKeyboardFunc( keyboard );
  96.     }
  97.  
  98. /* Single buffered RGB */
  99.  
  100.     if (sr)
  101.     {
  102.         glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
  103.         glutInitWindowPosition(100, 300); 
  104.     glutInitWindowSize( 400, 100);
  105.         glutCreateWindow("Single Rgb");
  106.         glutDisplayFunc( drawSRscene );
  107.     glutKeyboardFunc( keyboard );
  108.     }
  109.  
  110. /* Double buffered cmap */
  111.  
  112.     if (di)
  113.     {
  114.         glutInitDisplayMode(GLUT_INDEX | GLUT_DOUBLE);
  115.         glutInitWindowPosition(100, 500); 
  116.     glutInitWindowSize( 400, 100);
  117.         glutCreateWindow("Double Cmap");
  118.         glutSetColor(5, 0.2, 0.5, 0.7);
  119.         glutDisplayFunc( drawDIscene );
  120.     glutKeyboardFunc( keyboard );
  121.     }
  122.  
  123. /* Double buffered RGB */
  124.  
  125.     if (dr)
  126.     {
  127.         glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  128.         glutInitWindowPosition(100, 700); 
  129.     glutInitWindowSize( 400, 100);
  130.         glutCreateWindow("Double Rgb");
  131.         glutDisplayFunc( drawDRscene );
  132.     glutKeyboardFunc( keyboard );
  133.     }
  134.  
  135.  
  136.     glutMainLoop();
  137. }
  138.